package src.tree.level_order;

import src.tree.TreeNode;

import java.util.ArrayDeque;

public class no104 {//二叉树的最大深度

    public int maxDepth(TreeNode root) {

        if (root == null) return 0;
        ArrayDeque<TreeNode> queue = new ArrayDeque<>();
        queue.offer(root);
        int depth = 0;

        while (!queue.isEmpty()) {
            int size = queue.size();
            depth++;
            while (size-- > 0) {
                TreeNode node = queue.poll();
                if (node.left != null) queue.offer(node.left);
                if (node.right != null) queue.offer(node.right);
            }
            //depth++;
        }
        return depth;

    }
}
